package day20170407;

import org.junit.Test;

public class SortChoiceTest {
	@Test
	public void choiceTest() throws Exception {
		int[] arrays = {1,2,3,4,5};
		boolean choice = choice(arrays);
		String str = choice ? "排序完成..." : "已经是有序的,不用进行排序";
		System.out.println(str);
	}
	
	public boolean choice(int[] arrays){
		//是否不用排序
		boolean result = false;
		int temp = 0;
		for(int i=0; i<arrays.length-1; i++){
			for(int k=i+1; k<=arrays.length-1; k++){
				if(arrays[i] > arrays[k]){
					result = true;
					temp = arrays[k];
					arrays[k] = arrays[i];
					arrays[i] = temp;
				}
			}
		}
		
		if(result){
			for(int i=0; i<arrays.length; i++){
				System.out.print(arrays[i]+" ");
			}
		}
		
		return result;
	}
}
